import request from "@/utils/request";
import qs from "qs";
import {
  fileDownLoad
} from '@/utils/data-utils';
import exportApi from './exportApi';
import {parseTime} from '@/utils/common';
// 类别获取
export function factorTypes() {
  return request({
    url: `/v1/ystq/searchYslb`,
    method: "get",
  });
}

// // 要素提取管理
export function getfactor(data) {
  return request({
    url: `/v1/ystq/extractYs`,
    method: "post",
    data: qs.stringify(data)
  });
}

// 主流程信息新增
export function addProcess(data) {
  return request({
    url: "/v1/flowMain",
    method: "post",
    data
  });
}
// 删除主流程
export function deleteProcess(id) {
  return request({
    url: `/v1/flowMain/${id}`,
    method: "delete"
  });
}


// 获取码表
export function getCodeList(type) {
  return request({
    url: `/api/codelist/code/${type}`,
    method: "get",
  });
}

// 获取码表树
export function getCodeListTree(type) {
  return request({
    url: `/api/codetree/code/${type}`,
    method: "get",
  });
}

// 案件人员信息保存
export function batchSaves(data) {
  return request({
    url: `/v1/caseUserInfo/batchSave`,
    method: "post",
    data
  });
}


// 获取人员信息
export function getPersonInfo(data) {
  return request({
    url: `/v1/caseUserInfo/callCkxxBySfzhs`,
    method: "post",
    data: qs.stringify(data)
  });
}

// 主流程信息管理-详情
export function getFlowDetail(id) {
  return request({
    url: `/v1/flowMain/${id}`,
    method: "get",
  });
}

// 案件人员信息管理-条件查询
export function caseUserInfoSearch(searchable) {
  return request({
    url: `/v1/caseUserInfo/search`,
    method: "post",
    data: qs.stringify(searchable)
  });
}

// 加载表码
export const getCodeDict = codeId => {
  return request({
    url: `/api/codelist/code/${codeId}`,
    method: 'GET'
  });
};

// 专题信息管理-根据主流程ID查询关联专题
export const findSubjectByFlowId = (data) => {
  return request({
    url: `/v1/subject/findSubjectByFlowId`,
    method: 'POST',
    data: qs.stringify(data)
  });
};

// 专题信息管理-历史修改记录查询
export const searchHistory = (data) => {
  return request({
    url: `/v1/caseUserInfo/searchHistory`,
    method: 'POST',
    data: qs.stringify(data)
  });
};

// 领导批示管理-查询领导批示列表
export const leaderCommentFindAll = (flowId) => {
  return request({
    url: `/v1/leaderComment/findAll/${flowId}`,
    method: 'GET'
  });
};

// 领导批示管理-主流程-查询领导批示列表
export const leaderCommentFindMy = (flowId) => {
  return request({
    url: `/v1/leaderComment/findMy/${flowId}`,
    method: 'GET'
  });
};

// 指令管理-根据主流程ID查询指令信息列表、签收数和反馈数
export const searchOrderList = (data) => {
  return request({
    url: `/v1/zl/search`,
    method: 'POST',
    data: qs.stringify(data)
  });
};

// 关联信息-系统推荐、关联Tab页（除手动关联外）
export const queryAllAssociationFlowList = (data) => {
  return request({
    url: `/v1/flowMain/queryAllAssociationFlowList`,
    method: 'POST',
    data: qs.stringify(data)
  });
};

// 关联信息-详情手动关联
export const queryManualAssociationFlowList = (data) => {
  return request({
    url: `/v1/flowMain/queryManualAssociationFlowList`,
    method: 'POST',
    data: qs.stringify(data)
  });
}


// 关联信息和专题
export const onToRelated = (data) => {
  return request({
    url: `/v1/flowMainAssociation`,
    method: 'post',
    data
  });
}


// 案件人员信息管-关联案事件人员信息列表
export const caseInfoSearchByGlFlow = (data) => {
  return request({
    url: `/v1/caseUserInfo/searchByGlFlow`,
    method: 'POST',
    data: qs.stringify(data)
  });
}

// 案件人员信息管理-导出人员
export const exportUserInfo = (data) => {
  return request({
    url: `/v1/caseUserInfo/exportUserInfo`,
    method: 'POST',
    data: qs.stringify(data),
    responseType: 'arraybuffer',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
    }
  });
}

// 下载附件
export const fileDownloadUrl = (options, id) => {
  return fileDownLoad({
    url: `${id}`,
    method: 'get',
    ...options
  });
}

// 签收
export const flowMainSignIn = (data) => {
  return request({
    url: `/v1/flowMainSignIn`,
    method: 'POST',
    data
  });
}

// 获取当日值守人员列表
export const findJrzs = () => {
  return request({
    url: `/v1/jqxx-approval/jrzs`,
    method: 'GET'
  });
}

// 获取当日指挥长列表
export const findDrzhz = () => {
  return request({
    url: `/v1/jqxx-approval/drzhz`,
    method: 'GET'
  });
}

// 首页信息接口管理-领导关注
export const leaderConcern = () => {
  return request({
    url: `/v1/indexInfo/leaderConcern`,
    method: 'GET'
  });
}

// 首页信息接口管理-局领导关注
export const stateLeaderConcern = () => {
  return request({
    url: `/v1/indexInfo/stateLeaderConcern`,
    method: 'GET'
  });
}


// 反馈--指令
export const signIn = (id) => {
  return request({
    url: `/v1/order/signIn/${id}`,
    method: 'GET'
  });
}


// 指令下发
export const toOrder = (data) => {
  return request({
    url: `/v1/zl`,
    method: 'POST',
    data
  });
}


// 指令管理-条件查询：指令流程
export const searchZlJsFk = (data) => {
  return request({
    url: `/v1/zl/searchZlJsFk`,
    method: 'POST',
    data: qs.stringify(data)
  });
}

// 流程呈批管理-指挥部领导列表
export const flowPostApprovalZhbld = () => {
  return request({
    url: `/v1/flowPostApproval/zhbld`,
    method: 'GET'
  });
}

// 流程呈批管理-局领导列表
export const flowPostApprovalJld = () => {
  return request({
    url: `/v1/flowPostApproval/jld`,
    method: 'GET'
  });
}

// 流程呈批管理-保存
export const flowPostApproval = (data) => {
  return request({
    url: `/v1/flowPostApproval`,
    method: 'POST',
    data
  });
}

// 案件人员信息管理-详情-涉及对象统计
export const userInfoStatistic = () => {
  return request({
    url: `/v1/caseUserInfo/userInfoStatistic`,
    method: 'GET'
  });
}

// 流程补录管理-保存
export const saveFlowReplenishInfo = (data) => {
  return request({
    url: `/v1/flowReplenishInfo`,
    method: 'POST',
    data
  });
}

// 流程补录管理-删除
export const deleteFlowReplenishInfo = (id) => {
  return request({
    url: `/v1/flowReplenishInfo/${id}`,
    method: 'DELETE'
  });
}

// 流程补录管理-条件查询
export const searchProcessSupplement = (data) => {
  return request({
    url: `/v1/flowReplenishInfo/search`,
    method: 'POST',
    data:qs.stringify(data)
  });
}

// 流程关注管理-保存
export const saveFlowConcern = (data) => {
  return request({
    url: `/v1/flowConcern`,
    method: 'POST',
    data
  });
}

// 流程关注管理-删除
export const deleteFlowConcern = (id) => {
  return request({
    url: `/v1/flowConcern/${id}`,
    method: 'DELETE'
  });
}
// 草稿箱直接上报
export const sendGrag = (id) => {
  return request({
    url: `/v1/flowMain/sendFlow/${id}`,
    method: 'put'
  });
}


// 查询主流程列表Tab标签显示数 
export const getProTabNums = (sourceType) => {
  return request({
    url: `/v1/flowMain/queryFlowMainListTabNum/${sourceType}`,
    method: 'get'
  });
}

// 根据指令接收ID签收指令
export const onSignIn = (id) => {
  return request({
    url: `/v1/zl/signIn/${id}`,
    method: 'get'
  });
}

// 获取签收反馈统计,获取详情
export const relatedFeedback = (data) => {
  return request({
    url: `/v1/zl/searchJs`,
    method: 'post',
    data: qs.stringify(data)
  });
}

// 获取指令信息
export const orderInfo = (data) => {
  return request({
    url: `/v1/zl/search`,
    method: 'post',
    data: qs.stringify(data)
  });
}

// 指令信息反馈
export const orderFeedback = (data) => {
  return request({
    url: `/v1/zlFk`,
    method: 'post',
    data
  });
}

// 获取请求研判默认接收单位代码
export const getDefaultDept = (data) => {
  return request({
    url: `/v1/jqxx-ypzl/qqyp-jsdwdm`,
    method: 'get',
    data
  });
}
// 公共接口管理-获取当前登录用户的加密身份证号
export const queryCurrentEncryptSfzh = () => {
  return request({
    url: `/v1/common/encrypt-sfzh`,
    method: 'GET'
  });
}

// 公共接口管理-获取当前登录用户所在单位的信息
export const queryCurrenDmDeptInfo = () => {
  return request({
    url: `/v1/common/queryCurrenDmDeptInfo`,
    method: 'GET'
  });
}

// 指令反馈管理New-根据主流程ID查询反馈信息
export const fetchFeedbackList = (data) => {
  return request({
    url: `/v1/zlFk/search`,
    method: 'POST',
    data: qs.stringify(data)
  });
}


// 110警情信息-110警情列表查询
export const fetchPoliceDetail = (id) => {
  return request({
    url: `/v1/jqxx/${id}`,
    method: 'GET'
  });
}

// 110警情研判指令-110警情详情（情报）（包含指令信息列表）
export const fetchYpzlDetail = (id, data) => {
  return request({
    url: `/v1/jqxx-ypzl/ypzldetail/${id}`,
    method: 'POST',
    data: qs.stringify(data)
  });
}

// 110警情研判指令-110警情详情（指挥）（包含指令信息列表）
export const fetchYpzlDetailCcurrentorg = (id, data) => {
  return request({
    url: `/v1/jqxx-ypzl/ypzldetail-currentorg/${id}`,
    method: 'POST',
    data: qs.stringify(data)
  });
}

// 110报警呈批单-呈批单详情
export const fetchJqxxApprovalDetail = (id) => {
  return request({
    url: `/v1/jqxx-approval/${id}`,
    method: 'GET'
  });
}

// 首页信息接口管理-信息统计
export const messageCensus = () => {
  return request({
    url: `/v1/indexInfo/messageCensus`,
    method: 'GET'
  });
}

// 首页信息接口管理-预警总数-待办/已办
export const yjxxSumTypeList = (data) => {
  return request({
    url: `/v1/indexInfo/yjxxSumTypeList`,
    method: 'POST',
    data: qs.stringify(data)
  });
}

// 预警总数
export const yjxxSum = () => {
  return request({
    url: `/v1/indexInfo/yjxxSum`,
    method: 'GET'
  });
};

// 查询-主流程补录模块-批示人列表
export const getApprovalers = () => {
  return request({
    url: `/v1/flowReplenishInfo/psr`,
    method: 'GET'
  });
};

// 根据查询条件判断是否存在
export const getExists= (data) => {
  return request({
    url: `/v1/subject/exists`,
    method: 'POST',
    data: qs.stringify(data)
  });
};

/**
 * 打印预案信息详情
 * @param id	String
 * 		预案ID
 */
export const printYaxx = (id, yamc, type) => {
  let curr_date = new Date();
  let pattern = "yyyyMMdd";
  // 获取当前时间
  curr_date = parseTime(curr_date, pattern);

  if (type == '1'){ // 公安要情呈报单
    getGayqCbdFile(id, yamc, curr_date);
  } else if (type == '2'){ // 报警呈批单
    getBjcpdFile(id, yamc, curr_date);
  } else { // 每日要情
    getMryqFile(id, yamc, curr_date);
  }
}

/**
 * 查询序列号
 */
export const getSerial = () => {
  new Promise((resolve) => {
    resolve('1111');
  })
}

/**
 * 查询公安要情呈报单
 */
function getGayqCbdFile(id, yamc, curr_date){
  request({
    url: `/v1/printYaxxDetail/${id}`,
    method: 'GET',
    responseType: "arraybuffer"
  }).then(async res=> {
    let serial = await getSerial();
    exportApi.download( res.data, (yamc || "公安要情呈报单") + curr_date + serial +".docx" );
  });
}

/**
 * 查询报警呈批单
 */
function getBjcpdFile(id, yamc, curr_date){
  request({
    url: `/v1/printYaxxDetail/${id}`,
    method: 'GET',
    responseType: "arraybuffer"
  }).then(async res=> {
    let serial = await getSerial();
    exportApi.download( res.data, (yamc || "公安要情呈报单") + curr_date + serial +".docx" );
  });
}

/**
 * 查询每日要情
 */
function getMryqFile(id, yamc, curr_date){
  request({
    url: `/v1/printYaxxDetail/${id}`,
    method: 'GET',
    responseType: "arraybuffer"
  }).then(async res=> {
    let serial = await getSerial();
    exportApi.download( res.data, (yamc || "公安要情呈报单") + curr_date + serial +".docx" );
  });
}